From: | Ben Hutchings |
Date: | 28 Aug 99 at 02:20:53 |
Subject: | Re: Re: ExecBase & 'RESET:starting PC' exception |
From: Ben Hutchings <womble@zzumbouk.demon.co.uk>
On Fri, Aug 27, 1999 at 08:07:59PM -0600, Laura Vance wrote:
> From: Laura Vance <vancel@amiga.nols.com>
>
> On Sat, 28 Aug 1999 01:30:57 +0100,
> Ben Hutchings <womble@zzumbouk.demon.co.uk> wrote about Re: [amiga-c] Re:
> ExecBase & 'RESET:starting PC' exception:
> >From: Ben Hutchings <womble@zzumbouk.demon.co.uk>
> >
> >On Sat, Aug 28, 1999 at 12:44:33AM +0100, Andrew Markwell wrote:
> >> From: Andrew Markwell <andrewmarkwell@ukonline.co.uk>
> >>
> >> On 27-Aug-99 did write:
> >> > From: Ben Hutchings <womble@zzumbouk.demon.co.uk>
> >> >
> >> > On Fri, Aug 27, 1999 at 12:42:39AM +0100, Andrew Markwell wrote:
> >> >> From: Andrew Markwell <andrewmarkwell@ukonline.co.uk>
> >> >>
> >> >> On 27-Aug-99 did write:
> >> >> From: Ben Hutchings <womble@zzumbouk.demon.co.uk>
> >
> ><snip>
> >> >>> You should use const char * here, not char *.
> >> >>>
> >> >> er, why?
> >> >
> >> > String literals are arrays of const char.
> >> >
> >> First I've heard of it.
> >
> >You doubt what I say? Perhaps you should find some decent documentation
> >on standard C or C++.
> >
> >For hysterical raisins, you are allowed to assign string literals to
> >objects of type char *. That's just a special case; it doesn't mean that
> >they are really arrays of char.
> >
>
> I know that I'm sticking my nose in a conversation where it's not welcome,
> but it seems to me that a char * is a pointer to the beginning of a null
> terminated array of type char.
char * is a pointer to char; it may point to just one char or to the
first element of an array of char, which may or may not be null-
terminated.
> Anything in double quotes can be of type char * if it's probably
> going to change.
String literals are constants; you are not allowed to change them.
> In the C and C++ classes that I've taken in college, they say to
> reserve the const char * for something that will definately not
> change.
That's not quite right. You use pointers of type const char * where
you do not need to modify the characters pointed to. The characters
being pointed to might not really be constant, and may be modifiable
from other parts of the program.
> And since we only saw a code fragment, we do not know that other
> string literals will not be passed into the error handling function.
Of course they may be, but that has no bearing on their type.